#ifndef __REDIS_POOL_H__
#define __REDIS_POOL_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <list>
#include <vector>
#include <queue>
#include <string>
#include "hiredis/hiredis.h"
#include "singleton.h"

class RedisClient {
public:
    redisReply          *reply;
    redisContext        *context;
public:
    RedisClient();
    virtual ~RedisClient();
	
    int init(std::string host, int port, int timeout = 0, std::string pass = "");
    int connect_redis();

    void deinit();
    int command(const char *format, ...);
    int command_spec(const char *format, ...);
    int is_array_return_ok();
    char* get_value_as_string(const char *key);
    int get_value_as_int(const char *key);
    long long get_value_as_int64(const char *key);
    float get_value_as_float(const char*key);
public:
	bool hget(const std::string& hashkey
		, const std::string& key
		, std::string& value);
	bool hset(const std::string& hashkey
		, const std::string& key
		, const std::string& value);
	bool hdel(const std::string& hashkey
		, const std::string& key);
	int hincrby(const std::string& hashkey
		, const std::string& key
		, int num = 1);
private:
    std::string	_host;
    int	_port;
    int	_timeout;
    std::string	_pass;
};

#define REDIS_CONN Singleton<RedisClient>::Instance()


#endif
